package com.example.springboot1.file;

/**
 * @author ckj
 * @description TODO
 * @date 2023-03-14 9:32
 */


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.stream.LongStream;
import java.util.stream.Stream;

public class FileProcessor {
    public static void main(String[] args) throws IOException {
        String filename = "E:/numbers.txt";
        // 读取文件并将每行拆分成数字列表
        Stream<String> lines = new BufferedReader(new FileReader(filename)).lines();
        Stream<long[]> nums = lines.map(line -> {
            String[] numStrs = line.split(",");
            return Stream.of(numStrs).mapToLong(Long::parseLong).toArray();
        });


        // 计算最大值、最小值和平均值
        long[] maxVal = nums.mapToLong(numsArr -> LongStream.of(numsArr).max().getAsLong()).toArray();
//        long[] minVal = nums.mapToLong(numsArr -> Stream.of(numsArr).min().getAsLong()).toArray();
//        double[] avgVal = nums.mapToDouble(numsArr -> Stream.of(numsArr).average().getAsDouble()).toArray();
//
//        // 打印结果
        System.out.println("Max value: " + LongStream.of(maxVal).max().getAsLong());
//        System.out.println("Min value: " + Stream.of(minVal).min().getAsLong());
//        System.out.println("Avg value: " + Stream.of(avgVal).average().getAsDouble());

    }
}

